//
//  SlowMovement.swift
//  HIextractLicve
//
//  Created by HIextractLicve on 2024/12/9.
//

import UIKit
import ProgressHUD

class SlowMovement: UIViewController {
    var mindfulness:Set<Int>?
    var suggestion:Set<String>?
    var  professionals:Set<CGFloat>?
    var exchangeHTLC:[String:Array<Dictionary<String,String>>]?

    @IBOutlet weak var sendBgiVieHTLC: UIView!
    
    @IBOutlet weak var counyBgiVieHTLC: UIView!
    
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        let customized = "1customized0".components(separatedBy: "customized")
        let banlanceHTLC =  Int(HTLCAllDealRelaxing.Relaxing.signinUserDataHTL["HTLCcoin"] ?? customized[1]) ?? 0
        
       
            self.mineBlanceHTL.text = "\(banlanceHTLC)"
        
       
        
        
    }
    
    
    var chatDigloglistShowing:HTLROOOMMeasg?
  
    var recorSendGittCount:Int = 1
    var recorGittid:Int = 0
    
    @IBOutlet weak var mineBlanceHTL: UILabel!
    @IBOutlet weak var minecoinIcone: UIImageView!
    
    
    @IBOutlet weak var bottomGiftViewHTLC: UIView!
    
    
    @IBOutlet weak var giftCountToLBl: UILabel!
    
    @IBOutlet weak var hidddenGiftViewButton: UIButton!
    
    
    @IBOutlet weak var suresendGiftBtnHTLC: UIButton!
    
    
    @IBOutlet weak var addCountBtnHTLC: UIButton!
    
    lazy var liverdkkChatHTLC: UITableView = {
        var heixiuBig = UITableView.init(frame: .zero, style: .plain)
        
        heixiuBig.dataSource = self
        heixiuBig.delegate = self
        heixiuBig.backgroundColor = .clear
        heixiuBig.rowHeight = UITableView.automaticDimension
        heixiuBig.contentInset = UIEdgeInsets.init(top: 0, left: 0, bottom:bommbsafeHeitHTL + 90, right: 0)
        
        
        heixiuBig.register(ResilienceBuilding.self, forCellReuseIdentifier: "HTLCroomeLiveNormalCellID")
        heixiuBig.register(HTLCroomeLiveGiftCell.self, forCellReuseIdentifier: "HTLCroomeLiveGiftCellID")
        heixiuBig.estimatedRowHeight = 48
       
            heixiuBig.separatorStyle = .none
            heixiuBig.allowsSelection = false
        
       
        heixiuBig.showsVerticalScrollIndicator = false
        return heixiuBig
    }()
    
    var liveHTLCusserdata:Dictionary<String,String>
    init(stressdescHTL:Set<Int>,liveHTLCusserdata: Dictionary<String, String>) {
        self.liveHTLCusserdata = liveHTLCusserdata
        
        
    
        
        super.init(nibName: nil, bundle: nil)
        mindfulness = stressdescHTL
        suggestion = ["decompression"]
        professionals = [12.1]
        exchangeHTLC = ["themtopicHTLC":[["decompression":"098"]]]
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private let likeattiButtonHTLC = UIButton.init()
    private let giftButtonHTLC = UIButton.init()
    
    
    @IBOutlet weak var htlSeeCountlfbl: UILabel!
    
    
    @IBOutlet weak var htlLiveIconlfbl: UILabel!
    
    
    @IBOutlet weak var liveCVoverHTL: UIImageView!
    

    
    
    
    @IBOutlet weak var userHeaderHTL: UIButton!
    
    @IBOutlet weak var usernamhrHTl: UILabel!
    
    @IBOutlet weak var userfolloewrCoutHTL: UILabel!
    
    
    @IBOutlet weak var norinfobg0: UIView!
    
    @IBOutlet weak var normalinfobg1: UIView!
    
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        
        counyBgiVieHTLC.layer.cornerRadius = 22
        counyBgiVieHTLC.layer.maskedCorners = [.layerMinXMinYCorner,.layerMinXMaxYCorner]
      
            norinfobg0.layer.cornerRadius = 25
        
       
        norinfobg0.layer.maskedCorners = [.layerMaxXMaxYCorner,.layerMaxXMinYCorner]
    }
    
    @IBAction func morecTouchHTLC(_ sender: Any) {
        
            self.navigationController?.pushViewController(UntentionSetting(), animated: true)
        
       
    }
    
 
    
    @objc func userheaderTouch()  {
       
        let dymusercenterVC = NnnerCalmtrn.init(stressdescHTL: [456,456,456], passonHtlacData: liveHTLCusserdata)
        
        self.navigationController?.pushViewController(dymusercenterVC, animated: true)
    }
    
    @objc func likeattiButtonHTLCTouch()  {
        
        ProgressHUD.animate()
        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
            ProgressHUD.dismiss()
           
            self.likeattiButtonHTLC.isSelected = !self.likeattiButtonHTLC.isSelected
            HTLCAllDealRelaxing.Relaxing.revertHTLMyLikeToBroastLIVEbroad(stressdescHTL: [456,456,456], whoseDYMHTL: self.liveHTLCusserdata, islikejHTL: self.likeattiButtonHTLC.isSelected)
        }
       
       
    }
    
    
    @IBOutlet weak var moreiconTouchHTLC: UIButton!
    @objc func hidddenGiftView()  {
        bottomGiftViewHTLC.isHidden = true
     
        sendBgiVieHTLC.isHidden = true
        self.mineBlanceHTL.isHidden = true
     
        minecoinIcone.isHidden = true
        
        self.recorGittid = 0
        self.recorSendGittCount = 1
        self.giftCountToLBl.text = "x1"
        self.addlayoerwithGuft()
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let customized = "1customized0".components(separatedBy: "customized")
        NotificationCenter.default.addObserver(self, selector: #selector(diBakissBoockHTLC), name: NSNotification.Name("htldeleteuser"), object: nil)
       
        self.likeattiButtonHTLC.isSelected = (self.liveHTLCusserdata["stressCoping"] == customized[0])
        
        
        sendBgiVieHTLC.layer.cornerRadius = 22
        sendBgiVieHTLC.layer.masksToBounds = true
        
        hidddenGiftViewButton.addTarget(self, action: #selector(hidddenGiftView), for: .touchUpInside)
        liveCVoverHTL.layer.masksToBounds = true
      
        
        
        normalinfobg1.layer.cornerRadius = 10
        normalinfobg1.layer.masksToBounds = true
        
        htlLiveIconlfbl.layer.cornerRadius = 10
        htlLiveIconlfbl.layer.masksToBounds = true
        
        userHeaderHTL.layer.cornerRadius = 16
        userHeaderHTL.layer.masksToBounds = true
        
        htlSeeCountlfbl.text = liveHTLCusserdata["HtlcViewCoiutn"]
        
        liveCVoverHTL.image = UIImage(named: liveHTLCusserdata["HTLLiveCover"]  ?? "")
        userHeaderHTL.setImage(UIImage(named: liveHTLCusserdata["HTLCAvater"]  ?? ""), for: .normal)
        usernamhrHTl.text = liveHTLCusserdata["HTLCkiName"]
        
        userfolloewrCoutHTL.text = (liveHTLCusserdata["HTLCFollowercount"] ?? customized[1]) + " Followers"
        
        
        
        let texfieldChatHTL = UITextField.init()
        texfieldChatHTL.returnKeyType = .send
        texfieldChatHTL.delegate = self
        texfieldChatHTL.layer.masksToBounds = true
        texfieldChatHTL.textColor = .white
        texfieldChatHTL.backgroundColor =  UIColor(red: 0, green: 0, blue: 0, alpha:0.6)
        texfieldChatHTL.leftViewMode = .always
        texfieldChatHTL.leftView = UIView(frame: CGRect.init(x: 0, y: 0, width: 25.xHTL, height: 52.xHTL))
        
        texfieldChatHTL.layer.cornerRadius = 24.xHTL
        texfieldChatHTL.attributedPlaceholder = NSAttributedString.init(string: "Say something......", attributes: [NSAttributedString.Key.foregroundColor : UIColor.white])
        
        giftButtonHTLC.setBackgroundImage(UIImage.init(named: "giftbuihtlc"), for: .normal)
        likeattiButtonHTLC.setBackgroundImage(UIImage.init(named: "emptyzan_htlc"), for: .normal)
        likeattiButtonHTLC.setBackgroundImage(UIImage.init(named: "fillzanhtlc"), for: .selected)
        
        view.insertSubview(liverdkkChatHTLC, belowSubview: self.bottomGiftViewHTLC)
        view.insertSubview(giftButtonHTLC, belowSubview: self.bottomGiftViewHTLC)
        view.insertSubview(likeattiButtonHTLC, belowSubview: self.bottomGiftViewHTLC)
        view.insertSubview(texfieldChatHTL, belowSubview: self.bottomGiftViewHTLC)
        
        
        liverdkkChatHTLC.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            
            
            make.top.equalTo(norinfobg0.snp.bottom).offset(200.yHTL)
        }
        giftButtonHTLC.snp.makeConstraints { make in
            make.width.height.equalTo(48.xHTL)
            make.trailing.equalToSuperview().offset(-12.xHTL)
            make.bottom.equalToSuperview().offset(-bommbsafeHeitHTL - 8)
        }
        
        likeattiButtonHTLC.snp.makeConstraints { make in
            make.width.height.equalTo(48.xHTL)
            make.trailing.equalTo(giftButtonHTLC.snp.leading).offset(-16.xHTL)
            make.bottom.equalToSuperview().offset(-bommbsafeHeitHTL - 8)
        }
        
        texfieldChatHTL.snp.makeConstraints { make in
            make.leading.equalToSuperview().inset(12)
            make.height.equalTo(48.xHTL)
            make.bottom.equalToSuperview().offset(-bommbsafeHeitHTL - 8)
            make.trailing.equalTo(likeattiButtonHTLC.snp.leading).offset(-26.xHTL)
        }
        ProgressHUD.animate()
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.0, execute: DispatchWorkItem(block: {
            
            if let frgrgr = HTLCAllDealRelaxing.Relaxing.houseDialoglistHTL.filter({ HTLROOMMesgDiao in
                return HTLROOMMesgDiao.userDataHTLCinfo["natureImmersion"] == self.liveHTLCusserdata["natureImmersion"]
            }).first {
                self.chatDigloglistShowing = frgrgr
                print(frgrgr)
            }
            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1, execute: DispatchWorkItem(block: {
               
                    ProgressHUD.dismiss()
                
               
                self.liverdkkChatHTLC.reloadData()
            }))
        }))
        
        
        giftButtonHTLC.addTarget(self, action: #selector(giftButtonHTLCShowing), for: .touchUpInside)
        addCountBtnHTLC.addTarget(self, action: #selector(addCountGift), for: .touchUpInside)
        suresendGiftBtnHTLC.addTarget(self, action: #selector(sendGiftMeag), for: .touchUpInside)
        userHeaderHTL.addTarget(self, action: #selector(userheaderTouch), for: .touchUpInside)
        
        likeattiButtonHTLC.addTarget(self, action: #selector(likeattiButtonHTLCTouch), for: .touchUpInside)
        
        self.addlayoerwithGuft()
    }
    
    
    
    private func addlayoerwithGuft()  {
        let virew0 = self.bottomGiftViewHTLC.viewWithTag(1000)
        let virew1 = self.bottomGiftViewHTLC.viewWithTag(1001)
        let virew2 = self.bottomGiftViewHTLC.viewWithTag(1002)
        let virew3 = self.bottomGiftViewHTLC.viewWithTag(1003)
        let virew4 = self.bottomGiftViewHTLC.viewWithTag(1004)
        let virew5 = self.bottomGiftViewHTLC.viewWithTag(1005)
        let virew6 = self.bottomGiftViewHTLC.viewWithTag(1006)
        let virew7 = self.bottomGiftViewHTLC.viewWithTag(1007)
        let virew8 = self.bottomGiftViewHTLC.viewWithTag(1008)
        let virew9 = self.bottomGiftViewHTLC.viewWithTag(1009)
        virew0?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ChangeGiftTouch(tapg:))))
        virew1?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ChangeGiftTouch(tapg:))))
        virew2?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ChangeGiftTouch(tapg:))))
        virew3?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ChangeGiftTouch(tapg:))))
        virew4?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ChangeGiftTouch(tapg:))))
        virew5?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ChangeGiftTouch(tapg:))))
        virew6?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ChangeGiftTouch(tapg:))))
        virew7?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ChangeGiftTouch(tapg:))))
        virew8?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ChangeGiftTouch(tapg:))))
        virew9?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ChangeGiftTouch(tapg:))))
       
        
        
        virew0?.layer.cornerRadius =  15
        virew0?.layer.masksToBounds = true
        
        virew1?.layer.cornerRadius =  15
        virew1?.layer.masksToBounds = true
        
        virew2?.layer.cornerRadius =  15
        virew2?.layer.masksToBounds = true
        
        virew3?.layer.cornerRadius =  15
        virew3?.layer.masksToBounds = true
        
        virew4?.layer.cornerRadius =  15
        virew4?.layer.masksToBounds = true
        
        virew5?.layer.cornerRadius =  15
        virew5?.layer.masksToBounds = true
        
        virew6?.layer.cornerRadius =  15
        virew6?.layer.masksToBounds = true
    
        virew7?.layer.cornerRadius =  15
        virew7?.layer.masksToBounds = true
        
        virew8?.layer.cornerRadius =  15
        virew8?.layer.masksToBounds = true
        
        virew9?.layer.cornerRadius =  15
        virew9?.layer.masksToBounds = true
        
        virew0?.layer.borderWidth = 1
        virew0?.layer.borderColor = UIColor(red: 1, green: 0.01, blue: 0.33, alpha: 1).cgColor
        
        virew1?.layer.borderWidth = 0
        virew1?.layer.borderColor = UIColor(red: 1, green: 0.01, blue: 0.33, alpha: 1).cgColor
        
        virew2?.layer.borderWidth = 0
        virew2?.layer.borderColor = UIColor(red: 1, green: 0.01, blue: 0.33, alpha: 1).cgColor
        
        virew3?.layer.borderWidth = 0
        virew3?.layer.borderColor = UIColor(red: 1, green: 0.01, blue: 0.33, alpha: 1).cgColor
        
        virew4?.layer.borderWidth = 0
        virew4?.layer.borderColor = UIColor(red: 1, green: 0.01, blue: 0.33, alpha: 1).cgColor
        
        virew5?.layer.borderWidth = 0
        virew5?.layer.borderColor = UIColor(red: 1, green: 0.01, blue: 0.33, alpha: 1).cgColor
        
        virew6?.layer.borderWidth = 0
        virew6?.layer.borderColor = UIColor(red: 1, green: 0.01, blue: 0.33, alpha: 1).cgColor
    
        virew7?.layer.borderWidth = 0
        virew7?.layer.borderColor = UIColor(red: 1, green: 0.01, blue: 0.33, alpha: 1).cgColor
        
        virew8?.layer.borderWidth = 0
        virew8?.layer.borderColor = UIColor(red: 1, green: 0.01, blue: 0.33, alpha: 1).cgColor
        
        virew9?.layer.borderWidth = 0
        virew9?.layer.borderColor = UIColor(red: 1, green: 0.01, blue: 0.33, alpha: 1).cgColor
        
        
    }

    
    @IBAction func Funrightnoweback(_ sender: Any) {
      
            self.navigationController?.popViewController(animated: true)
        
       
    }
    
    @objc func diBakissBoockHTLC()  {
        
            self.navigationController?.popViewController(animated: true)
        
        
        
    }
   @objc func giftButtonHTLCShowing()  {
       self.bottomGiftViewHTLC.isHidden = false
       sendBgiVieHTLC.isHidden = false
       self.mineBlanceHTL.isHidden = false
       self.mineBlanceHTL.isHidden = false
       minecoinIcone.isHidden = false
    }
    
   
    
}


extension SlowMovement:UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
       
        return chatDigloglistShowing?.mesgHTLasarry.count ?? 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        
        if let diologData = self.chatDigloglistShowing?.mesgHTLasarry[indexPath.row]{

            if diologData.isgiftmesg == true {
                let giftCell = tableView.dequeueReusableCell(withIdentifier: "HTLCroomeLiveGiftCellID", for: indexPath) as! HTLCroomeLiveGiftCell
                giftCell.userHeaderHTL.image = (diologData.0) ? HTLCAllDealRelaxing.Relaxing.showingHTLimgHead :  UIImage(named:  diologData.1["HTLCAvater"] ?? "")
                giftCell.usernamhrHTl.text = (diologData.0) ? "Me" :  (diologData.1["HTLCkiName"] ?? "")
                giftCell.giftCountLblHTl.text = "x\(diologData.giftCount ?? 0)"
                
                giftCell.giftcontentIConHTl.image = UIImage(named: "gifter\(diologData.giftID ?? 0)HTL")
               
                
                return giftCell
            }else{
                let chateCell = tableView.dequeueReusableCell(withIdentifier: "HTLCroomeLiveNormalCellID", for: indexPath) as! ResilienceBuilding
               
                chateCell.userHeaderHTL.image = (diologData.0) ? HTLCAllDealRelaxing.Relaxing.showingHTLimgHead :  UIImage(named:  diologData.1["HTLCAvater"] ?? "")

                
                chateCell.usernamhrHTl.text = (diologData.0) ? "Me" :  (diologData.1["HTLCkiName"] ?? "")
                chateCell.saycontentHTl.text =  diologData.2
                return chateCell
            }
        }
        
       
        return UITableViewCell.init()
    }
    
    
    
    
    //发送正常消息
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
      
       
        textField.resignFirstResponder()
        
            if let conted = textField.text, conted.count != 0 {
                let diologdata = (true,HTLCAllDealRelaxing.Relaxing.signinUserDataHTL,conted,false,0,0)
                
                chatDigloglistShowing?.mesgHTLasarry.append(diologdata)
          
                textField.text = nil
                textField.resignFirstResponder()
                
                ProgressHUD.animate()
               
                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.0, execute: DispatchWorkItem(block: {
                    ProgressHUD.dismiss()
                 
                        self.liverdkkChatHTLC.reloadData()
                    
                  
                    
                    
                    
                    for(i, item) in HTLCAllDealRelaxing.Relaxing.houseDialoglistHTL.enumerated() {
                        if  let melost = self.chatDigloglistShowing, item.userDataHTLCinfo["natureImmersion"] == self.liveHTLCusserdata["natureImmersion"] {
                          
                            
                            HTLCAllDealRelaxing.Relaxing.houseDialoglistHTL[i] = melost
                        }
                    }
                    
                }))
                
                
                
            }else{
              
                    ProgressHUD.banner(HTLROOOMMeasg.BinrwetioBase64("QSBlbXB0eSBtZXNzYWdlIGNhbm5vdCBiZSBzZW5kISEh"), HTLROOOMMeasg.BinrwetioBase64("QSBwcm9tcHQgbWVzc2FnZQ=="), delay: 2.0)
                
                
              
            }
            
            
            
            
            
           
        
        return true
    }
    
   
}


extension SlowMovement{
    
   @objc func addCountGift() {
       self.recorSendGittCount += 1
       self.giftCountToLBl.text = "x\(recorSendGittCount)"
   
   }
    
    @objc func sendGiftMeag() {
        let customized = "1customized0".components(separatedBy: "customized")
        var banlanceHTLC = Int(HTLCAllDealRelaxing.Relaxing.signinUserDataHTL["HTLCcoin"] ?? customized[1]) ?? 0
        let needBlance = self.recorSendGittCount * 100
        
        if banlanceHTLC < needBlance {
            let alertv = UIAlertController(title: "Insufficient gold coins", message: "", preferredStyle: .alert)
            let scdtion = UIAlertAction(title: "Recharge", style: .default) { scd in
                self.navigationController?.pushViewController(MindBodyConnection(), animated: true)
            }
            alertv.addAction(scdtion)
            alertv.addAction(UIAlertAction(title: "Cancel", style: .default))
            self.present(alertv, animated: true)
            return
        }
        
        // 扣除金币
        banlanceHTLC -= needBlance
        HTLCAllDealRelaxing.Relaxing.signinUserDataHTL["HTLCcoin"] = "\(banlanceHTLC)"
        self.mineBlanceHTL.text = "\(banlanceHTLC)"
        
        // ✅ 这里 giftID / giftCount 保持 Int
        let userData = HTLCAllDealRelaxing.Relaxing.signinUserDataHTL.compactMapValues { "\($0)" }
        let diologdata: (Bool, [String:String], String, Bool?, Int?, Int?) =
            (true, userData, "", true, recorGittid, recorSendGittCount)
        
        chatDigloglistShowing?.mesgHTLasarry.insert(diologdata, at: 0)
        
        ProgressHUD.animate()
        self.hidddenGiftView()
        
        DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
            ProgressHUD.dismiss()
            self.liverdkkChatHTLC.reloadData()
            
            for (i, item) in HTLCAllDealRelaxing.Relaxing.houseDialoglistHTL.enumerated() {
                if let melost = self.chatDigloglistShowing,
                   item.userDataHTLCinfo["natureImmersion"] == self.liveHTLCusserdata["natureImmersion"] {
                    HTLCAllDealRelaxing.Relaxing.houseDialoglistHTL[i] = melost
                }
            }
        }
    }


    
    
    @objc func ChangeGiftTouch(tapg:UITapGestureRecognizer)  {
        let virew0 = self.bottomGiftViewHTLC.viewWithTag(1000)
        let virew1 = self.bottomGiftViewHTLC.viewWithTag(1001)
        let virew2 = self.bottomGiftViewHTLC.viewWithTag(1002)
        let virew3 = self.bottomGiftViewHTLC.viewWithTag(1003)
        let virew4 = self.bottomGiftViewHTLC.viewWithTag(1004)
        let virew5 = self.bottomGiftViewHTLC.viewWithTag(1005)
        let virew6 = self.bottomGiftViewHTLC.viewWithTag(1006)
        let virew7 = self.bottomGiftViewHTLC.viewWithTag(1007)
        let virew8 = self.bottomGiftViewHTLC.viewWithTag(1008)
        let virew9 = self.bottomGiftViewHTLC.viewWithTag(1009)
        
      
        
        self.recorGittid = (tapg.view?.tag ?? 1000) - 1000
        if tapg.view == virew0 {
            
            virew0?.layer.borderWidth = 1
            
            virew1?.layer.borderWidth = 0
            virew2?.layer.borderWidth = 0
            virew3?.layer.borderWidth = 0
            virew4?.layer.borderWidth = 0
            virew5?.layer.borderWidth = 0
            virew6?.layer.borderWidth = 0
            virew7?.layer.borderWidth = 0
            virew8?.layer.borderWidth = 0
            virew9?.layer.borderWidth = 0
        }else if tapg.view == virew1{
            
            virew1?.layer.borderWidth = 1
            
            virew0?.layer.borderWidth = 0
            virew2?.layer.borderWidth = 0
            virew3?.layer.borderWidth = 0
            virew4?.layer.borderWidth = 0
            virew5?.layer.borderWidth = 0
            virew6?.layer.borderWidth = 0
            virew7?.layer.borderWidth = 0
            virew8?.layer.borderWidth = 0
            virew9?.layer.borderWidth = 0
        }else if tapg.view == virew2{
            
            virew2?.layer.borderWidth = 1
            
            virew0?.layer.borderWidth = 0
            virew1?.layer.borderWidth = 0
            virew3?.layer.borderWidth = 0
            virew4?.layer.borderWidth = 0
            virew5?.layer.borderWidth = 0
            virew6?.layer.borderWidth = 0
            virew7?.layer.borderWidth = 0
            virew8?.layer.borderWidth = 0
            virew9?.layer.borderWidth = 0
        }else if tapg.view == virew3{
            
            virew3?.layer.borderWidth = 1
             
            virew0?.layer.borderWidth = 0
            virew1?.layer.borderWidth = 0
            virew2?.layer.borderWidth = 0
            virew4?.layer.borderWidth = 0
            virew5?.layer.borderWidth = 0
            virew6?.layer.borderWidth = 0
            virew7?.layer.borderWidth = 0
            virew8?.layer.borderWidth = 0
            virew9?.layer.borderWidth = 0
        }else if tapg.view == virew4{
            
            virew4?.layer.borderWidth = 1
            
            virew0?.layer.borderWidth = 0
            virew2?.layer.borderWidth = 0
            virew3?.layer.borderWidth = 0
            virew1?.layer.borderWidth = 0
            virew5?.layer.borderWidth = 0
            virew6?.layer.borderWidth = 0
            virew7?.layer.borderWidth = 0
            virew8?.layer.borderWidth = 0
            virew9?.layer.borderWidth = 0
        }else if tapg.view == virew5{
            
            virew5?.layer.borderWidth = 1
            virew0?.layer.borderWidth = 0
            virew2?.layer.borderWidth = 0
            virew3?.layer.borderWidth = 0
            virew4?.layer.borderWidth = 0
            virew1?.layer.borderWidth = 0
            virew6?.layer.borderWidth = 0
            virew7?.layer.borderWidth = 0
            virew8?.layer.borderWidth = 0
            virew9?.layer.borderWidth = 0
        }else if tapg.view == virew6{
            
            virew6?.layer.borderWidth = 1
            
            virew0?.layer.borderWidth = 0
            virew2?.layer.borderWidth = 0
            virew3?.layer.borderWidth = 0
            virew4?.layer.borderWidth = 0
            virew5?.layer.borderWidth = 0
            virew1?.layer.borderWidth = 0
            virew7?.layer.borderWidth = 0
            virew8?.layer.borderWidth = 0
            virew9?.layer.borderWidth = 0
        }else if tapg.view == virew7{
            
            virew7?.layer.borderWidth = 1
             
            virew0?.layer.borderWidth = 0
            virew2?.layer.borderWidth = 0
            virew3?.layer.borderWidth = 0
            virew4?.layer.borderWidth = 0
            virew5?.layer.borderWidth = 0
            virew6?.layer.borderWidth = 0
            virew1?.layer.borderWidth = 0
            virew8?.layer.borderWidth = 0
            virew9?.layer.borderWidth = 0
        }else if tapg.view == virew8{
            
            virew8?.layer.borderWidth = 1
             
            virew0?.layer.borderWidth = 0
            virew2?.layer.borderWidth = 0
            virew3?.layer.borderWidth = 0
            virew4?.layer.borderWidth = 0
            virew5?.layer.borderWidth = 0
            virew6?.layer.borderWidth = 0
            virew7?.layer.borderWidth = 0
            virew1?.layer.borderWidth = 0
            virew9?.layer.borderWidth = 0
        }else if tapg.view == virew9{
            
            virew9?.layer.borderWidth = 1
             
            virew0?.layer.borderWidth = 0
            virew2?.layer.borderWidth = 0
            virew3?.layer.borderWidth = 0
            virew4?.layer.borderWidth = 0
            virew5?.layer.borderWidth = 0
            virew6?.layer.borderWidth = 0
            virew7?.layer.borderWidth = 0
            virew8?.layer.borderWidth = 0
            virew1?.layer.borderWidth = 0
        }
        
        
        
        
     }
}
